package com.wind.trademark.user.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wind.trademark.base.vo.NodeVo;
import com.wind.trademark.common.vo.PageBean;
import com.wind.trademark.common.vo.PageParam;
import com.wind.trademark.user.model.AccRole;
import com.wind.trademark.user.service.RoleService;
@Controller
public class RoleController {
	@Autowired
	private RoleService roleService;
	
	private static final Log log = LogFactory.getLog(RoleController.class);


	@RequestMapping
	public @ResponseBody PageBean  queryRole(PageParam pageParam,@RequestParam Map<String, Object> params) {
		PageBean pageBean=roleService.queryRole(pageParam,params);
		return pageBean;
	}
	@RequestMapping
	public @ResponseBody List<AccRole>  getAllRoles() {
		List<AccRole> roles=roleService.getAllRoles();
		return roles;
	}
	@RequestMapping
	public @ResponseBody  AccRole saveOrUpdateRole( AccRole role){
		return roleService.saveOrUpdateRole(role);
	}
	@RequestMapping
	public @ResponseBody  AccRole loadRole(Long id){
		return roleService.getRole(id);
	}
	@RequestMapping
	public @ResponseBody  List<NodeVo> loadPermissionsByRoleId(Long roleId) {
		List<NodeVo> nodeVoList= roleService.loadPermissionsByRoleId(roleId);
		return nodeVoList;
	}
	@RequestMapping
	public @ResponseBody  boolean saveOrUpdateRolePermission(Long roleId,Long[] permissions) {
		 roleService.saveOrUpdateRolePermission(roleId,Arrays.asList(permissions));
		 return true;
	}
}
